import type { DynamicProps } from '/#/utils';
import type { BasicTableProps, BasicColumn } from '/@/components/Table/src/types/table';
import { FormProps } from '/@/components/Table';
import { searchSchemas } from './searchData';
import { comQueryParams } from '/@/extendModel/gatewayModel';
import { getDeviceTypeListApi } from '/@/api/sys/gateway/gateway';
type Props = Partial<DynamicProps<BasicTableProps>>;
import moment from 'moment';
// 列配置
const tableColumns: BasicColumn[] = [
  {
    title: '型号编码',
    dataIndex: 'code',
    fixed: 'left',
    width: 50,
  },
  {
    title: '型号名称',
    dataIndex: 'name',
    fixed: 'left',
    width: 130,
  },

  {
    title: '创建时间',
    dataIndex: 'create_time',
    width: 100,
  },
];

export const formConfig: Partial<FormProps> = {
  labelWidth: 100,
  schemas: searchSchemas,
  actionColOptions: {
    span: 8,
    style: { textAlign: 'left', marginLeft: '40px' },
  },
};

export const tableConfig: Props = {
  api: getData,
  columns: tableColumns,
  useSearchForm: true,
  formConfig: formConfig,
  showTableSetting: true,
  tableSetting: { fullScreen: true },
  showIndexColumn: false,
  rowKey: 'id',
  bordered: true,
  fetchSetting: {
    totalField: 'total',
    listField: 'list',
    sizeField: 'page_size',
  },
  actionColumn: {
    width: 150,
    title: '操作',
    slots: { customRender: 'action' },
  },
};

export async function getData(params: comQueryParams): Promise<any> {
  const brand_id = localStorage.getItem('brand_id');
  if (brand_id) {
    params.brand_id = brand_id || '';
    const res: any = await getDeviceTypeListApi(params);
    res.list.map((item) => {
      item.create_time = moment(parseInt(item.create_time) * 1000).format('YYYY-MM-DD');
    });
    return res.list;
  }
}
